package com.example.hotelmanagement.service;

import com.example.hotelmanagement.entity.User;
import com.example.hotelmanagement.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    // 注册用户
    public boolean registerUser(User user) {
        int result = userMapper.insertUser(user);
        return result > 0; // 返回是否成功
    }

    // 用户认证
    public User authenticate(String username, String password) {
        User user = userMapper.findByUsername(username);
        if (user != null && user.getPassword().equals(password)) {
            return user;
        }
        return null; // 返回 null 表示认证失败
    }

    // 根据用户ID获取用户
    public User getUserById(Long userId) {
        return userMapper.findById(userId);
    }

    // 更新用户信息
    public boolean updateUser(User user) {
        int result = userMapper.updateUser(user);
        return result > 0; // 返回是否成功
    }

    // 删除用户
    public boolean deleteUser(Long userId) {
        int result = userMapper.deleteUser(userId);
        return result > 0; // 返回是否成功
    }
}
